using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;

namespace XGame.UI
{
    public class DragTouch : MonoBehaviour,IPointerClickHandler,IDragHandler,IPointerExitHandler
    {
        void IDragHandler.OnDrag(PointerEventData eventData)
        {
            _ONDrag?.Invoke(eventData.delta);

            _Darging = true;
        }
        bool  _Darging;

        void IPointerClickHandler.OnPointerClick(PointerEventData eventData)
        {
            if (_Darging)
            {
                _Darging = false;
                return;
            } 

            _ONClick?.Invoke();
        }
        void IPointerExitHandler.OnPointerExit(PointerEventData eventData)
        {
            _Darging = false;
        }
        // Start is called before the first frame update
        void Start()
        {

        }

        // Update is called once per frame
        void Update()
        {

        }
        public  UnityEvent<Vector2> _ONDrag;
        public DragTouch WaitDrag(UnityAction<Vector2> _on)
        {
            _ONDrag.AddListener(_on);
            return this;
        }
        public UnityEvent _ONClick;
        public DragTouch WaitClick(UnityAction _on)
        {
            _ONClick.AddListener(_on);
            return this;
        }

 
    }
}

